home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / NET / IRDA / IRQUEUE.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  111 lines

  1. /*********************************************************************
  2.  *                
  3.  * Filename:      irqueue.h
  4.  * Version:       0.3
  5.  * Description:   General queue implementation
  6.  * Status:        Experimental.
  7.  * Author:        Dag Brattli <dagb@cs.uit.no>
  8.  * Created at:    Tue Jun  9 13:26:50 1998
  9.  * Modified at:   Thu Feb 25 20:34:21 1999
  10.  * Modified by:   Dag Brattli <dagb@cs.uit.no>
  11.  * 
  12.  *     Copyright (C) 1998, Aage Kvalnes <aage@cs.uit.no>
  13.  *     Copyright (c) 1998, Dag Brattli
  14.  *     All Rights Reserved.
  15.  *      
  16.  *     This code is taken from the Vortex Operating System written by Aage
  17.  *     Kvalnes and has been ported to Linux and Linux/IR by Dag Brattli
  18.  *
  19.  *     This program is free software; you can redistribute it and/or 
  20.  *     modify it under the terms of the GNU General Public License as 
  21.  *     published by the Free Software Foundation; either version 2 of 
  22.  *     the License, or (at your option) any later version.
  23.  *  
  24.  *     Neither Dag Brattli nor University of Troms° admit liability nor
  25.  *     provide warranty for any of this software. This material is 
  26.  *     provided "AS-IS" and at no charge.
  27.  *     
  28.  ********************************************************************/
  29.  
  30. #include <linux/types.h>
  31. #include <asm/spinlock.h>
  32.  
  33. /* #include <net/irda/irda.h> */
  34.  
  35. #ifndef QUEUE_H
  36. #define QUEUE_H
  37.  
  38. #define NAME_SIZE      32
  39.  
  40. /*
  41.  * Hash types
  42.  */
  43. #define HB_NOLOCK      0
  44. #define HB_GLOBAL      1
  45. #define HB_LOCAL       2
  46. #define HB_SORTED      4
  47.  
  48. /*
  49.  * Hash defines
  50.  */
  51. #define HASHBIN_SIZE   8
  52. #define HASHBIN_MASK   0x7
  53.  
  54. #ifndef ALIGN 
  55. #define ALIGN __attribute__((aligned))
  56. #endif
  57.  
  58. typedef void (*FREE_FUNC)( void *arg);
  59.  
  60. /*
  61.  * Hashbin
  62.  */
  63. #define GET_HASHBIN(x) ( x & HASHBIN_MASK )
  64.  
  65. #define QUEUE struct queue_t
  66. struct queue_t {
  67.     QUEUE* q_next;
  68.     QUEUE* q_prev;
  69.  
  70.     char   q_name[ NAME_SIZE];
  71.     __u32  q_hash;
  72. };
  73.  
  74. typedef struct hashbin_t {
  75.     int    magic;
  76.     int    hb_type;
  77.     int    hb_size;
  78.     spinlock_t hb_mutex[ HASHBIN_SIZE ] ALIGN;
  79.     QUEUE*     hb_queue[ HASHBIN_SIZE ] ALIGN;
  80.  
  81.     QUEUE* hb_current;
  82. } hashbin_t;
  83.  
  84. hashbin_t *hashbin_new( int type);
  85. int      hashbin_delete( hashbin_t* hashbin, FREE_FUNC func);
  86. int      hashbin_clear( hashbin_t* hashbin, FREE_FUNC free_func);
  87. void     hashbin_insert( hashbin_t* hashbin, QUEUE* entry, __u32 hashv, 
  88.              char* name);
  89. void*    hashbin_find( hashbin_t* hashbin, __u32 hashv, char* name);
  90. void*    hashbin_remove( hashbin_t* hashbin, __u32 hashv, char* name);
  91. void*    hashbin_remove_first( hashbin_t *hashbin);
  92. QUEUE   *hashbin_get_first( hashbin_t *hashbin);
  93. QUEUE   *hashbin_get_next( hashbin_t *hashbin);
  94.  
  95. void enqueue_last(QUEUE **queue, QUEUE* element);
  96. void enqueue_first(QUEUE **queue, QUEUE* element);
  97. QUEUE *dequeue_first(QUEUE **queue);
  98.  
  99. /*
  100.  * Function hashbin_get_size (hashbin)
  101.  *
  102.  *    Returns the number of elements in the hashbin
  103.  *
  104.  */
  105. extern __inline__ int  hashbin_get_size( hashbin_t* hashbin) 
  106. {
  107.     return hashbin->hb_size;
  108. }
  109.  
  110. #endif
  111.